<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>Coco Message Example</title>
    <style>
        body {
            margin: 0;
        }

        #test {
            margin: 0 auto;
            width: 1000px;
            height: calc(160vh - 100px);
            display: flex;
            justify-content: center;
            align-items: center;
        }

        #test button {
            margin: 0 20px;
        }

        .coco-btn {
            font-size: 14px;
            text-decoration: none;
            padding: 6px 20px;
            white-space: nowrap;
            border-radius: 5px;
            font-weight: 500;
            display: inline-block;
            cursor: pointer;
            border: 0;
            -webkit-appearance: none;
            -moz-appearance: none;
            appearance: none;
            line-height: normal;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }

        .coco-btn.cancel {
            margin-right: 10px;
            color: #525456;
            background-color: transparent;
            font-weight: 500;
            transition: all 0.06s ease-out;
        }

        .coco-btn,
        .coco-btn span,
        .coco-loading {
            position: relative;
        }

        .coco-btn.ok {
            background-color: #0077ff;
            color: #fefefe;
        }

        .coco-btn.ok::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            border-radius: inherit;
            transition: all 0.12s ease-out;
            background-color: transparent;
        }

        .coco-btn.ok:hover::before {
            background-color: rgba(255, 255, 255, 0.08);
        }

        .coco-btn.ok:active::before {
            transition: all 80ms ease-out;
            background-color: rgba(0, 0, 0, 0.2);
        }

        .github {
            font-weight: 600;
            text-align: center;
            margin-top: 100px;
        }
    </style>
</head>
<body>

<div id="test">
    <button class="coco-btn ok">信息</button>
    <button class="coco-btn ok">成功</button>
    <button class="coco-btn ok">警告</button>
    <button class="coco-btn ok">错误</button>
    <button class="coco-btn ok">加载</button>
    <button class="coco-btn ok">closeAll</button>
</div>
<script src="./coco-message.js"></script>
<script>
    "use strict";

    Message.config({
        duration: 10000,
    });
    var btns = document.body.querySelectorAll(".coco-btn.ok");

    for (var i = 0; i < btns.length; i++) {
        addClickEvent(btns[i], i);
    }

    function addClickEvent(btn, i) {
        btn.addEventListener("click", function () {
            example(i);
        });
    }

    function example(n) {
        switch (n) {
            case 0:
                Message.info(3000, "请先登录！", function () {
                    console.log("close");
                });
                break;

            case 1:
                var div1 = document.createElement("div");
                div1.innerText = "修改成功！";
                Message.success(div1);
                break;

            case 2:
                Message.warning("需要手动关闭", 0);
                break;

            case 3:
                Message.error("修改失败！", 3000);
                break;

            case 4:
                var closeMsg = Message.loading(true);
                setTimeout(function () {
                    closeMsg();
                }, 4000);
                break;

            case 5:
                Message.destroyAll();
                break;

            default:
                break;
        }
    }
</script>
</body>
</html>
